/*
Copyright (C) 2009-2010 Xanadu Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "../provider/DataProvider.h"
#include "PlayerSkills.h"
#include "Player.h"
#include "Skill.h"
#include "../client/SkillData.h"
#include "../client/SkillLevelData.h"
#include <iostream>

PlayerSkills::~PlayerSkills() {
	for (hash_map<int,Skill*>::iterator iter = skills.begin(); iter != skills.end(); iter++)
		delete iter->second;
}

void PlayerSkills::addSkill(Skill* skill) {
	skills[skill->getID()] = skill;
}

Skill* PlayerSkills::getSkill(int skillid) {
	if(skills.find(skillid) != skills.end())
		return skills[skillid];
	if (skillid == 1004 || skillid == 1003 || skillid == 8) {
		Skill* nskill = new Skill(skillid, 0, 1);
		skills[skillid] = nskill;
		return nskill;
	} else {
		SkillData* skilld = DataProvider::getInstance()->getSkillData(skillid);
		if(skilld == 0) {
			cout << "[PlayerSkills]:Failed to get data for Skill: " << skillid << ", PlayerID: " << player->getID() << endl;
			return 0;
		}
		Skill* nskill = new Skill(skillid, 0, (isFourthJob(skillid)) ? 0 : skilld->getCount());
		skills[skillid] = nskill;
		return nskill;
	}
}

int PlayerSkills::getSkillLevel(int skillid) {
	Skill* skill = getSkill(skillid);
	if(skill != 0)
		return skill->getLevel();
	return 0;
}

int PlayerSkills::getMpEater() {
	int skillid = 0;
	switch (player->getJob()) {
		case 210:
		case 211:
		case 212:
			skillid = 2100000;
			break;
		case 220:
		case 221:
		case 222:
			skillid = 2200000;
			break;
		case 230:
		case 231:
		case 232:
			skillid = 2300000;
			break;
	}
	return skillid;
}
short PlayerSkills::getMasteryBonus(){
	short bonus = 0;
	short level = getSkillLevel(4100000);
	if(level > 0){
	SkillLevelData* mastery = DataProvider::getInstance()->getSkillData(4100000)->getDataByID(level);
		bonus = mastery->getY();
	}
	return bonus;
}

int PlayerSkills::getincHPID()
{
	short jobid = player->getJob();
	if (jobid >= 100 && jobid < 200)
	{
		return 1000006;
	}
	if (jobid >= 1510 && jobid < 1600)
	{
		return 15100007;
	}
	if (jobid >= 510 && jobid < 600)
	{
		return 5100009;
	}
	if (jobid >= 1100 && jobid < 1200)
	{
		return 12000005;
	}
	if (jobid >= 1200 && jobid < 1300)
	{
		return 12000005;
	}
	if (jobid >= 2000 && jobid < 3000)
	{
		return 20000006;
	}
	return 0;
	/*
	switch(jobid)
	{
	case 1510:
		return 15100007;break;
	case 100:
		return 1000006;break;
	case 510:
		return 5100009;break;
	case 1100:
		return 11000005;break;
	case 1200:
		return 12000005;break;
	case 200:
		return 20000006;break;
	default:
		return 0;break;
	}*/
}

int PlayerSkills::getincMPID()
{
	short jobid = player->getJob();
	switch(jobid)
	{
	case 1200:
		return 12000005;break;
	case 200:
		return 2000006;break;
	default:
		return 0;break;
	}
}